package com.sh.深浅拷贝;

public class Main {
    public static void main(String[] args) {
        Address address = new Address("上海");
        Person p1 = new Person("小明", address);

        Person p2 = p1.shallowCopy();  // 浅拷贝
        Person p3 = p1.deepCopy();

        System.out.println("原始：" + p1.address.city);
        System.out.println("浅拷贝：" + p2.address.city);
        System.out.println("深拷贝：" + p3.address.city);

        // 修改原始地址
        p1.address.city = "北京";

        System.out.println("\n修改后：");
        System.out.println("原始：" + p1.address.city);
        System.out.println("浅拷贝：" + p2.address.city); // 也变了
        System.out.println("深拷贝：" + p3.address.city); // 没变
    }
}